Spot-On
spot-on-smp.h
1 /*
2 ** Copyright (c) 2011 - 10^10^10, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from Spot-On without specific prior written permission.
15 **
16 ** SPOT-ON IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** SPOT-ON, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef _spoton_smp_h_
29 #define _spoton_smp_h_
30 
31 #include <QByteArray>
32 #include <QList>
33 #include <QString>
34 
35 extern "C"
36 {
37 #include <gcrypt.h>
38 }
39 
40 class spoton;
41 
43 {
44  public:
46  ~spoton_smp(void);
47  static const unsigned int BITS = 1536;
48  static gcry_mpi_t generateWeakRandomPrime(bool *ok);
49  static void test1(void);
50  static void test2(void);
51  static void test3(void);
52  static void test4(void);
53  QByteArray guessSha(void) const;
54  QByteArray guessWhirlpool(void) const;
55  QList<QByteArray> coordinatesProof(const gcry_mpi_t g2,
56  const gcry_mpi_t g3,
57  const gcry_mpi_t r,
58  const int version,
59  bool *ok) const;
60  QList<QByteArray> equalLogs(const gcry_mpi_t qab,
61  const gcry_mpi_t x,
62  const int version,
63  bool *ok) const;
64  QList<QByteArray> logProof(const gcry_mpi_t g,
65  const gcry_mpi_t x,
66  const int version,
67  bool *ok) const;
68  QList<QByteArray> nextStep(const QList<QByteArray> &other,
69  bool *ok,
70  bool *passed);
71  QList<QByteArray> step1(bool *ok);
72 
73  QString guessString(void) const
74  {
75  return m_guessString;
76  }
77 
78  bool passed(void) const;
79  bool verifyCoordinatesProof(const QList<QByteArray> &list,
80  const gcry_mpi_t g2,
81  const gcry_mpi_t g3,
82  const gcry_mpi_t p,
83  const gcry_mpi_t q,
84  const int version) const;
85  bool verifyEqualLogs(const QList<QByteArray> &list,
86  const gcry_mpi_t g3,
87  const gcry_mpi_t qab,
88  const gcry_mpi_t r,
89  const int version) const;
90  bool verifyLogProof(const QList<QByteArray> &list,
91  const gcry_mpi_t g,
92  const gcry_mpi_t x,
93  const int version) const;
94  int step(void) const;
95  void initialize();
96  void setGuess(const QString &guess);
97 
98  void setModulus(const gcry_mpi_t modulus)
99  {
100  gcry_mpi_release(m_modulus);
101  m_modulus = gcry_mpi_copy(modulus);
102  }
103 
104  void setStep0(void)
105  {
106  m_step = 0;
107  }
108 
109  private:
110  QString m_guessString;
111  bool m_passed;
112  char *m_guessWhirl; // Stored in secure memory.
113  gcry_mpi_t m_a2;
114  gcry_mpi_t m_a3;
115  gcry_mpi_t m_b2;
116  gcry_mpi_t m_b3;
117  gcry_mpi_t m_g2b;
118  gcry_mpi_t m_g3a;
119  gcry_mpi_t m_g3b;
120  gcry_mpi_t m_generator;
121  gcry_mpi_t m_guess;
122  gcry_mpi_t m_modulus;
123  gcry_mpi_t m_order;
124  gcry_mpi_t m_pa;
125  gcry_mpi_t m_pb;
126  gcry_mpi_t m_qab;
127  gcry_mpi_t m_qb;
128  int m_step;
129  size_t m_guessWhirlLength;
130  spoton *m_spoton;
131  static const int TERMINAL_STATE = -1;
132  QList<QByteArray> step2(const QList<QByteArray> &other, bool *ok);
133  QList<QByteArray> step3(const QList<QByteArray> &other, bool *ok);
134  QList<QByteArray> step4(const QList<QByteArray> &other,
135  bool *ok,
136  bool *passed);
137  gcry_mpi_t generateRandomExponent(bool *ok) const;
138  void reset(void);
139  void step5(const QList<QByteArray> &other, bool *ok, bool *passed);
140 };
141 
142 #endif
spoton
Definition: spot-on.h:433
spoton_smp
Definition: spot-on-smp.h:42